import { BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { FormSchema } from '/@/components/Form';
import { useUserStore } from '/@/store/modules/user';
import moment from 'moment';
import { useI18n } from '/@/hooks/web/useI18n';

import { Getallpersondto } from '/@/api/demo/system';

const { t } = useI18n();
const useCommonStore = useUserStore();

// 表单模板搜索
export function searchFormSchema(): Partial<FormProps> {
  return {
    labelWidth: 100,
    colon: false, // 是否显示冒号
    schemas: [
      {
        field: `documentName`,
        label: t('routes.demo.documentManager.formTemplate.documentName'),
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
        componentProps: {
          placeholder: t('routes.demo.documentManager.formTemplate.documentIdPlaceholder'),
        },
      },
    ],
  };
}

// 选择表单模板表格
export function selectTableColumns(): BasicColumn[] {
  return [
    {
      title: '表单模板名称',
      dataIndex: 'name',
      fixed: 'left',
      width: 200,
    },
    {
      title: '模板分类',
      dataIndex: 'dataType',
      width: 100,
    },
    {
      title: '创建人',
      dataIndex: 'creater',
      width: 100,
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      width: 150,
      slots: { customRender: 'createTime' },
    },
  ];
}

// 表单模板表格
export function tableColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.documentManager.formTemplate.documentId'),
      dataIndex: 'documentId',
      fixed: 'left',
      width: 200,
    },
    {
      title: t('routes.demo.documentManager.formTemplate.documentName'),
      dataIndex: 'documentName',
      width: 100,
    },
    {
      title: t('routes.demo.documentManager.formTemplate.type'),
      dataIndex: 'type',
      width: 100,
    },
    {
      title: t('routes.demo.documentManager.formTemplate.encoderAssociation'),
      dataIndex: 'encoderAssociation',
      width: 150,
    },
    {
      title: t('routes.demo.documentManager.formTemplate.produceSoftware'),
      dataIndex: 'produceSoftware',
      width: 150,
    },
  ];
}

// 提交表单
export function getAddForm(): FormSchema[] {
  return [
    {
      field: 'documentId',
      component: 'Input',
      label: t('routes.demo.documentManager.formTemplate.documentId'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.documentManager.formTemplate.documentIdPlaceholder'),
      },
    },
    {
      field: 'documentName',
      component: 'Input',
      label: t('routes.demo.documentManager.formTemplate.documentName'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.documentManager.formTemplate.documentNamePlaceholder'),
      },
    },
    {
      field: 'type',
      component: 'Select',
      label: t('routes.demo.documentManager.formTemplate.type'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.documentManager.formTemplate.typePlaceholder'),
        options: [
          { label: '表单模板1', value: '1' },
          { label: '表单模板2', value: '2' },
        ],
      },
    },
    {
      field: 'encoderAssociation',
      component: 'Select',
      label: t('routes.demo.documentManager.formTemplate.encoderAssociation'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.documentManager.formTemplate.encoderAssociationPlaceholder'),
        options: [
          { label: '表单模板1', value: '1' },
          { label: '表单模板2', value: '2' },
        ],
      },
    },
    {
      field: 'produceSoftware',
      component: 'Select',
      label: t('routes.demo.documentManager.formTemplate.produceSoftware'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.documentManager.formTemplate.produceSoftwarePlaceholder'),
        options: [
          { label: '表单模板1', value: '1' },
          { label: '表单模板2', value: '2' },
        ],
      },
    },
  ];
}

// 借阅表单
export function getBorrowForm(): FormSchema[] {
  return [
    {
      field: 'oid',
      component: 'Input',
      label: '图档内部流水号',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      show: false,
      componentProps: {
        placeholder: '请输入图档内部流水号',
        defaultValue: '',
      },
    },
    {
      field: 'ThitObjectId',
      component: 'Input',
      label: '图档代号',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      show: false,
      componentProps: {
        placeholder: '请输入图档代号',
        defaultValue: '',
      },
    },
    {
      field: 'name',
      component: 'Input',
      label: '图档名称',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      show: false,
      componentProps: {
        placeholder: '请输入图档名称',
        defaultValue: '借阅表单',
      },
    },
    {
      field: 'version',
      component: 'Input',
      label: '版本',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入版本',
        defaultValue: '1',
        disabled: true,
      },
    },
    {
      field: 'creater',
      component: 'Input',
      label: '创建人',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入创建人',
        defaultValue: useCommonStore.userInfo?.userId,
        disabled: true,
      },
    },
    {
      field: 'createtime',
      component: 'DatePicker',
      label: '创建日期',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入创建日期',
        // 获取当前日期
        defaultValue: moment(new Date()),
        disabled: true,
      },
    },
    {
      field: 'filename',
      component: 'Input',
      label: '源文件名',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入源文件名',
        defaultValue: '',
        disabled: true,
      },
    },
    {
      field: 'securitylevel',
      component: 'Input',
      label: '安全级别',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入安全级别',
        defaultValue: '3',
        disabled: true,
      },
    },
    {
      field: 'status',
      component: 'Input',
      label: '状态',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入状态',
        defaultValue: '1',
        disabled: true,
      },
    },
    {
      field: 'filetype',
      component: 'Input',
      label: '文件类型',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入文件类型',
        defaultValue: '',
        disabled: true,
      },
    },
    {
      field: 'BorrowStartTime',
      component: 'DatePicker',
      label: '借阅开始时间',
      required: true,
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入借阅开始时间',
      },
    },
    {
      field: 'BorrowEndTime',
      component: 'DatePicker',
      label: '借阅结束时间',
      required: true,
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入借阅结束时间',
      },
    },
    {
      field: 'BorrowReason',
      component: 'InputTextArea',
      label: '借阅原因',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入借阅原因',
        defaultValue: '',
      },
    },
    {
      field: 'BrowserDetails',
      component: 'InputTextArea',
      label: '借阅描述',
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入借阅描述',
        defaultValue: '',
      },
    },
    {
      field: 'Browser',
      component: 'ApiSelect',
      label: '借阅人',
      required: true,
      colProps: {
        xl: 12,
        xxl: 12,
      },
      componentProps: {
        placeholder: '请输入借阅人',
        api: Getallpersondto,
        labelField: 'name',
        valueField: 'id',
      },
    },
  ];
}
